import { defineMock } from "./base";
import Mock from "mockjs";

const articlesList = (data: any) => {
  return Mock.mock({
    "total|100-300": 300,
    "rows|10": [
      {
        "id|+1": 1,
        cover:
          data.cover ||
          "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif?imageView2/1/w/80/h/80",
        heading: data.heading || "@cparagraph(2)",
        content:
          "<p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p>",
        "articlePicture|1-10": 10,
        "articleVedio|1-10": 10,
        "categoryId|1-10": 10,
        "readTime|1-100": 10,
        author: data.author || "@cname",
        uploadTime: "@now('yyyy-MM-dd')T@now('HH:00:00')",
        lastModifyTime: "@now('yyyy-MM-dd')T@now('HH:mm:ss')",
      },
    ],
  });
};

const articles = (data: any) => {
  return Mock.mock([
    {
      id: data.id,
      cover:
        data.cover ||
        "https://foruda.gitee.com/images/1723603502796844527/03cdca2a_716974.gif?imageView2/1/w/80/h/80",
      heading: data.heading || "@cparagraph(2)",
      content:
        "<p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p><p>@cparagraph(10,100)</p>",
      "articlePicture|1-10": 10,
      "articleVedio|1-10": 10,
      "categoryId|1-10": 10,
      "readTime|1-100": 10,
      author: data.author || "@cname",
      uploadTime: "@now('yyyy-MM-dd')T@now('HH:00:00')",
      lastModifyTime: "@now('yyyy-MM-dd')T@now('HH:mm:ss')",
    },
  ]);
};

export default defineMock([
  {
    url: "/docs",
    method: ["GET"],
    body: ({ query, params }) => {
      return {
        code: 1,
        data: articlesList({ ...query }),
        msg: "success",
      };
    },
  },
  {
    url: "/docs",
    method: ["PUT", "POST"],
    body: ({ query, params }) => {
      return {
        code: 1,
        data: null,
        msg: "success",
      };
    },
  },
  {
    url: "/docs/:id",
    method: ["DELETE"],
    body: {
      code: 1,
      data: null,
      msg: "success",
    },
  },
  {
    url: "/docs/:id",
    method: ["GET"],
    body: ({ query, params }) => {
      return {
        code: 1,
        data: articles({
          ...params,
        }),
        msg: "success",
      };
    },
  },
]);
